Visual Basic 2003: Code  

Code: Creating a Registry Key and Setting Its Values (Visual Basic)

This example creates a registry key, SOFTWARE\\Microsoft\\TestApp\\1.0, and sets its values.

Example

Private Sub CreateAndSetKey
    Dim regVersion As Microsoft.Win32.RegistryKey
    regVersion = _
Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\TestApp\\1.0")
    Dim newVersion As Integer = 0
    If (Not regVersion Is Nothing) Then
        newVersion = Microsoft.Win32.regVersion.GetValue("Version", 0)
        newVersion = newVersion + 1
        regVersion.SetValue("Version", newVersion)
        regVersion.Close()
    End If
End Sub

Compiling the Code

This example requires:

Security

Registry calls fail if either sufficient runtime permissions are not granted (RegistryPermission Class) or if the user does not have the correct ACLs for creating or writing to settings. For example, a local application that has the code access security permission might not have operating system permission.

See Also

Code: Creating a Key In the Registry (Visual Basic) | Registry Access Changes in Visual Basic .NET | Registry Class | Registry Summary | System Input/Output Example Topics